package com.example.toolproject.demo.service.serviceimpl;

import com.example.toolproject.demo.domain.PlanningReport;
import com.example.toolproject.demo.domain.PlanningReportScore;
import com.example.toolproject.demo.mapper.PlanningReportMapper;
import com.example.toolproject.demo.mapper.UserEvaluationMapper;
import com.example.toolproject.demo.service.PlanningReportService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName PlanningReportServiceImpl
 * @Description TODO
 * @Author lvyongwei
 * @Date 2020-06-28 14:31
 **/
@Service
public class PlanningReportServiceImpl implements PlanningReportService {

    @Autowired
    private PlanningReportMapper planningReportMapper;

    @Autowired
    private UserEvaluationMapper userEvaluationMapper;

    /**
     * 策划报告的撰写
     * @param planningReport  策划报告实体
     * @return
     */
    @Override
    public boolean insertPlanReport(PlanningReport planningReport) {
        return planningReportMapper.insertPlanReport(planningReport);
    }

    /**
     * 根据用户id查询用户的撰写报告
     * @param userId
     * @return
     */
    @Override
    public PlanningReport getPlanningByUserId(int userId) {
        return planningReportMapper.getPlanningByUserId(userId);
    }

    /**
     * 根据时间获取时间最新的十条策划报告
     * @return
     */
    @Override
    public List<PlanningReport> getAllPlanningReportByTime() {
        return planningReportMapper.getAllPlanningReportByTime();
    }

    /**
     * 根据分数获取分数最高的十条策划报告
     * @return
     */
    @Override
    public List<PlanningReport> getAllPlanningReportByScore() {
        return planningReportMapper.getAllPlanningReportByScore();
    }

    /**
     * 根据撰写的报告的id获取撰写的报告
     * @param planningReportId
     * @return
     */
    @Override
    public PlanningReport getPlanningReportById(long planningReportId) {
        return planningReportMapper.getPlanningReportById(planningReportId);
    }

    /**
     * 自评成绩
     * @param projectId    撰写的报告的id
     * @param selfEvaluation    自评的成绩
     * @return
     */
    @Override
    public boolean updateSelfEvaluation(double selfEvaluation, long projectId) {
        return planningReportMapper.updateSelfEvaluation(selfEvaluation, projectId);
    }

    /**
     * 获取所有策划报告信息
     * @param userId    用户id
     * @param roleId    角色id
     * @param message   搜索信息
     * @return
     */
    @Override
    public List<PlanningReport> getAllPlanningReport(Integer userId, Integer roleId, String message) {
        return planningReportMapper.getAllPlanningReport(userId,roleId,message);
    }

    /**
     * 删除策划报告记录
     * @param planningReportId  策划报告id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deletePlanningReport(long planningReportId) {
        /**
         * 删除策划报告，同时删除对策划报告的评论
         */
        userEvaluationMapper.deleteUserEvaluation(planningReportId);
        return planningReportMapper.deletePlanningReport(planningReportId);
    }

    /**
     * 获取策划报告成绩分布
     * @return
     */
    @Override
    public PlanningReportScore getPlanningReportScore() {
        return planningReportMapper.getPlanningReportScore();
    }
}
